package com.supermarket;

import com.supermarket.dao.CommodityDao;
import com.supermarket.dao.SupplierDao;
import com.supermarket.utils.ScannerUtil;
import com.supermarket.view.CommodityView;
import com.supermarket.view.StockView;
import com.supermarket.view.SupplierView;

public class Main {
    //创建窗口对象
    private static CommodityView commodityView = new CommodityView();
    private static StockView stockView = new StockView();
    private static SupplierView supplierView = new SupplierView();

    //数据库设置
    private static String DB_URL = "jdbc:mysql://150.138.78.97:9002/mallsellsystem?serverTimezone=UTC&useSSL=false&requireSSL=false";
    private static String DB_USER = "MallSellSystem";
    private static String DB_PASSWORD = "123456";

    //静态代码块
    static {
        MySQLSetting();
    }
    //主方法
    public static void main(String[] args) {
        mainMenu();
    }

    //主窗口
    public static void mainMenu() {
        while (true) {
            System.out.println("========================");
            System.out.println("欢迎来到超市进销存管理系统");
            System.out.println("=========================");
            System.out.println("1. 商品管理");
            System.out.println("2. 库存管理");
            System.out.println("3. 供应商管理");
            System.out.println("0. 退出系统");
            System.out.println("=========================");
            System.out.println("请输入菜单序号：");
            int result = ScannerUtil.getInt();
            switch (result) {
                case 1:
                    commodityView.CommodityView();
                    break;
                case 2:
                    stockView.StockView();
                    break;
                case 3:
                    supplierView.SupplierView();
                    break;
                case 0:
                    System.exit(0);
                    break;
                default:
                    System.out.println("您输入的菜单序号不正确，请重新输入！");
                    break;
            }
        }
    }

    //数据库设置方法
    private static void MySQLSetting() {
        CommodityDao.MySQLSettingForCommodity(DB_URL, DB_USER, DB_PASSWORD);
        SupplierDao.MySQLSettingForSupplier(DB_URL, DB_USER, DB_PASSWORD);
    }
}

